package com.yuand.service.impl;

import com.yuand.entity.SysUser;
import com.yuand.mapper.SysMenuMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author yuandong
 * @company KB
 * @create 2022-01-26 10:26
 * 收集用户的角色权限数据和perms
 */
@Component
@Slf4j
public class SysPermissionService {

	@Autowired
	private SysMenuMapper sysMenuMapper;

	/**
	 * 获取菜单数据权限
	 *
	 * @param user 用户信息
	 * @return 菜单权限信息
	 */
	public List<String> getMenuPermission(SysUser user)
	{
		List<String> perms = new ArrayList<>();
		/*// 管理员拥有所有权限
		if("1".equals(user.getUserType())){
			perms.add("*:*:*");
		}else{
			perms.addAll(this.sysMenuMapper.selectMenuPermsByUserId(user.getUserId()));
		}*/

		perms.addAll(this.sysMenuMapper.selectMenuPermsByUserId(user.getUserId()));

		log.info(user.getUsername()+"用户拥有的权限为："+perms);

		return perms;
	}
}
